package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.DataVerification;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysCopyright;
import com.ruoyi.system.service.ISysCopyrightService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 版权信息Controller
 *
 * @author ruoyi
 * @date 2022-04-06
 */
@RestController
@RequestMapping("/system/copyright")
public class SysCopyrightController extends BaseController
{
    @Autowired
    private ISysCopyrightService sysCopyrightService;

    /**
     * 查询版权信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:copyright:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysCopyright sysCopyright)
    {
        startPage();
        List<SysCopyright> list = sysCopyrightService.selectSysCopyrightList(sysCopyright);
        return getDataTable(list);
    }

    /**
     * 导出版权信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:copyright:export')")
    @Log(title = "版权信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysCopyright sysCopyright)
    {
        List<SysCopyright> list = sysCopyrightService.selectSysCopyrightList(sysCopyright);
        ExcelUtil<SysCopyright> util = new ExcelUtil<SysCopyright>(SysCopyright.class);
        util.exportExcel(response, list, "版权信息数据");
    }

    /**
     * 获取版权信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:copyright:query')")
    @GetMapping(value = "/{copyrightId}")
    public AjaxResult getInfo(@PathVariable("copyrightId") Long copyrightId)
    {
        return AjaxResult.success(sysCopyrightService.selectSysCopyrightByCopyrightId(copyrightId));
    }

    /**
     * 新增版权信息
     */
    @DataVerification(name = "添加版权信息")
    @PreAuthorize("@ss.hasPermi('system:copyright:add')")
    @Log(title = "版权信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysCopyright sysCopyright)
    {
        return toAjax(sysCopyrightService.insertSysCopyright(sysCopyright));
    }

    /**
     * 修改版权信息
     */
    @DataVerification(name = "修改版权信息")
    @PreAuthorize("@ss.hasPermi('system:copyright:edit')")
    @Log(title = "版权信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysCopyright sysCopyright)
    {
        return toAjax(sysCopyrightService.updateSysCopyright(sysCopyright));
    }

    /**
     * 删除版权信息
     */
    @PreAuthorize("@ss.hasPermi('system:copyright:remove')")
    @Log(title = "版权信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{copyrightIds}")
    public AjaxResult remove(@PathVariable Long[] copyrightIds)
    {
        return toAjax(sysCopyrightService.deleteSysCopyrightByCopyrightIds(copyrightIds));
    }

    /**
     * 获取版权信息详细信息
     */
    @GetMapping(value = "/getCopyrightInfo")
    public AjaxResult getCopyrightInfo()
    {
        return AjaxResult.success(sysCopyrightService.getCopyrightInfo());
    }
}
